package cn.jimmie.learn.viewArt.fragment

import android.text.Editable
import android.text.TextWatcher
import android.view.View
import cn.jimmie.learn.viewArt.R
import cn.jimmie.learn.viewArt.weight.AutoLineView
import kotlinx.android.synthetic.main.fragment_autoline.view.*

/**
 * function :
 *
 * <p> Create Time:  2019年01月15日 18:17 </p>
 * <p> @author Jimmie.Qian  </p>
 */

class AutoLineFragment : BaseFragment() {
    private var mView: AutoLineView? = null

    override fun layoutId(): Int = R.layout.fragment_autoline

    override fun initView(root: View) {
        root.editor.addTextChangedListener(textWatch)
        mView = root.my_view

        root.btn.setOnClickListener {
            mView!!.invalidate()
        }
    }

    private val textWatch = object : TextWatcher {
        override fun afterTextChanged(s: Editable) {
            val text = s.toString()
            mView!!.text = text
        }

        override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
        }

        override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
        }
    }
}